import type { FindLimitDto, FindList } from "./auth";

export enum StatusComment {
  Pass = "pass",
  Block = "block",
  Review = "review",
}

export interface Comment {
  id: number;
  ip: string;
  ua: string;
  avatar: string;
  email: string;
  name: string;
  replyName: string;
  replyEmail: string;
  status: StatusComment;
  suggestion: string;
  putTop: boolean;
  isAdmin: boolean;
  parent?: Comment;
  children?: Comment[];
  content: string;
  posts: number;
  createTime: Date;
  updateTime: Date;
}

export interface FindComment {
  id?: number;
  ip?: string;
  ua?: string;
  avatar?: string;
  email?: string;
  name?: string;
  replyName?: string;
  replyEmail?: string;
  status?: StatusComment | null;
  suggestion?: string;
  putTop?: boolean;
  isAdmin?: boolean;
  parent?: number;
  children?: number[];
  content?: string;
  resourceId?: string;
  createTime?: Date;
  updateTime?: Date;
}

export interface CommentQueryFind extends FindComment, FindLimitDto {}

export const findAll = (query?: CommentQueryFind) => {
  return useServerRequest<FindList<Comment>>("/comments", {
    method: "GET",
    params: { ...query },
  });
};

export const deleteById = (id: number) => {
  return useServerRequest(`/comments/${id}`, {
    method: "DELETE",
    body: {},
  });
};
